package com.party.admin.web.controller.analysis;

import com.google.common.collect.Maps;
import com.party.admin.web.dto.input.common.CommonInput;
import com.party.common.paging.Page;
import com.party.common.utils.StringUtils;
import com.party.core.model.analysis.StatisticsModulePVUV;
import com.party.core.model.analysis.StatisticsPageCounter;
import com.party.core.model.member.MemberGroup;
import com.party.core.model.system.TargetType;
import com.party.core.service.analysis.IStatisticsPageCountService;
import com.party.core.service.member.IMemberGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.*;

/**
 * @program: Project
 * @description: ModulePVUV控制器
 * @author: Huaqunhao
 * @create: 2018-09-19 18:12
 **/
@Controller
@RequestMapping("analysis/modulePVUV")
public class StatisticsModulePVUVController {
    @Autowired
    private IStatisticsPageCountService iStatisticsPageCountService;
    @Autowired
    private IMemberGroupService memberGroupService;


    /**
     * @Description: 模块分析列表
     * @Param:
     * @return:
     * @Author: Huaqunhao
     * @Date: 2018-09-19 18:12
     */
    @RequestMapping(value = "list")
    public ModelAndView list(Page page, StatisticsPageCounter pageCount, CommonInput commonInput) {
        ModelAndView mv = new ModelAndView("analysis/modulePVUVList");

        page.setLimit(10);
        if (commonInput.getTimeType() == null&&
                (StringUtils.isBlank(commonInput.getCreateEnd())||StringUtils.isBlank(commonInput.getCreateStart()))
                ){
            commonInput.setTimeType(2);
        }

        CommonInput.transfromDate(commonInput);
        Map<String, Object> params = Maps.newHashMap();
        params.put("startDate", commonInput.getCreateStart());
        params.put("endDate", commonInput.getCreateEnd());



        //获取modulePVUVs
        List<StatisticsModulePVUV> modulePVUVs =iStatisticsPageCountService.getModulePVUV(pageCount,params,page);
        //设置模块名
        for (StatisticsModulePVUV smpobj:modulePVUVs){
            smpobj.setModuleName(TargetType.getValue(smpobj.getModuleName()));
        }
        //获取合作商列表
        List<MemberGroup> partnerList = memberGroupService.getAllPartnerWithName();

        mv.addObject("page", page);
        mv.addObject("modulePVUVs", modulePVUVs);
        mv.addObject("partnerList", partnerList);
        mv.addObject("pageCount", pageCount);
        mv.addObject("modules", TargetType.values());
        mv.addObject("input", commonInput);
        return mv;
    }
}
